/**
 * @file
 * @author dousha
 * @date 2020
 */

#include "stm32f4xx.h"
#include "stm32f4xx_usart.h"

#include "debug.h"
#include "semihosting.h"
#include "../boilerplate/utils.h"
#include "../kernel/config.h"

void debug_write(const char *s) {
#ifdef KERNEL_DEBUG
#ifndef DEBUG_USE_SERIAL
	const uint32_t len = get_string_length(s);
	host_write(2, s, len);
#else
	// write to serial
#endif // DEBUG_USE_SERIAL
#endif // KERNEL_DEBUG
}

void debug_init() {
#ifdef DEBUG_USE_SERIAL
#ifdef DEBUG_USE_USB

#else
	// clock init
	// serial init
	USART_InitTypeDef usart;
	usart.USART_BaudRate = DEBUG_BAUD;
	usart.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
	usart.USART_Parity = USART_Parity_No;
	usart.USART_StopBits = USART_StopBits_1;
	usart.USART_WordLength = USART_WordLength_8b;
	USART_Init(DEBUG_SERIAL_PORT, &usart);
#endif // DEBUG_SERIAL_PORT
#endif
}
